(function () {
    var util = {};
    //var completeUrl = "http://new.yytaomeng.com/";
    util.completeUrl="http://192.168.1.11:80/";
    var interfaceList = [
        {id: 'selectbychoiceness', val: 'web/consult/selectbyrecommend'},
        {id:'insertone', val:'api/feed/insertone'},
        {id:'selectbyid',val:'api/user/selectbyid'},
        {id:'selectbytype',val:'api/user/selectbytype'},
        {id:'saveuserinfo',val:'api/user/saveuserinfo'},
        {id:'unread',val:'push/message/unread'},
        {id:'messageselectbytype',val:'push/message/selectbytype'},
        {id:'getbanner',val:'api/borrow/type/gettype'}

    ];
    //post请求方法
    util.ajax = function (key, data, success) {
        $.ajax({
            url: key.indexOf('http://') >= 0 ? key : util.interfaceUrl(key),
            data: data ? data : {},
            dataType: 'json',
            type: 'POST',
            jsonpCallback: "successCallback",
            async: true,
            success: success ? success : function () {
                }
        });
    };
    //get请求
    util.getAjax = function (key, data, success) {
        $.ajax({
            url: key.indexOf('http://') >= 0 ? key : util.interfaceUrl(key),
            data: data ? data : {},
            dataType: 'json',
            async: true,
            type: 'GET',
            contentType: "application/json; charset=utf-8",
            jsonpCallback: "successCallback",
            success: function (data) {
                if (data.status == 1) {
                    success(data.content);
                } else {
                    console.log('请求错误');
                }
            },
            error: function (e) {
                console.log(e);
            }
    });
    };
    //获取接口名称
    util.getInterface = function (key) {
        var value = '';
        $.each(interfaceList, function (n, val) {
            if (val.id == key) {
                value =util.completeUrl+ val.val;
                return false;
            }
        });
        return value;
    };

    //拼接接口路径
    util.interfaceUrl = function (url) {

        completeUrl = url.indexOf('http://') >= 0 ? url : util.getInterface(url);
        return completeUrl;
    };
    util.error = function (data) {

    };
    util.isNull=function(str) {
        while (str.lastIndexOf(" ") >= 0) {
            str = str.replace(" ", "");
        }
        while (str.lastIndexOf("&nbsp;") >= 0) {
            str = str.replace("&nbsp;", "");
        }
        if (str.length == 0) {
            return 1;
        }else{
            return 0;
        }
    }
    window.util = util;
})();



